package org.darcy.controller.work;

import org.darcy.entity.work.WorkInstance;
import org.darcy.entity.work.WorkTask;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.framework.model.R;
import org.darcy.service.work.WorkService;
import org.darcy.service.work.WorkTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Tag(name = "WorkTask接口：工作任务")
@RestController
@RequestMapping(value = "/WorkTask")
@Slf4j
public class WorkTaskController {

	private final String info_prefix = "[工作任务模块]";

	@Autowired
	private WorkService WorkService;

	@Autowired
	private WorkTaskService WorkTaskService;

	@Operation(summary = "工作任务分页列表")
	@PostMapping(value = "list")
	public R list(@RequestBody PageParam<WorkInstance> param) {
		log.debug("{}-列表数据", info_prefix);
		// param.getEntity().setStartOperator(UserTool.getLoginUserId());
		PageData<WorkInstance> data = WorkService.page(param);
		return R.ok().data(data);
	}

	@Operation(summary = "工作任务详情")
	@GetMapping("/view/{id}")
	public R view(@PathVariable Integer id) {
		log.debug("{}-查看工作任务信息", info_prefix);
		WorkInstance data = WorkService.getDetail(id);
		return R.ok().data(data);
	}

	@Operation(summary = "更新工作任务")
	@PostMapping("update")
	public R update(@RequestBody WorkInstance record) {
		log.debug("{}-保存信息: {}", info_prefix, record);
		WorkService.update(record);
		return R.ok("更新成功");
	}

	@Operation(summary = "查看工作任务属性")
	@GetMapping("/model")
	public WorkInstance model() {
		return null;
	}

	@Operation(summary = "工作任务审批")
	@PostMapping("approve")
	public R approve(@RequestBody WorkTask task) {
		log.debug("{}-工作任务审批: {}", info_prefix, task);
		WorkService.approve(task);
		return R.ok().data("工作任务审批成功");
	}

	@Operation(summary = "工作任务转交他人")
	@PostMapping("transfer")
	public R transfer(@RequestBody WorkTask task) {
		WorkTaskService.transfer(task);
		return R.ok("转交他人成功").data(task);
	}

}
